package com.neueduTotal.solar;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;

public class imageUtil {

    public static Map<String,Image> imgMap=new HashMap<>();

    static {
        imgMap.put("bg",imageUtil.getImage("background.png"));
        imgMap.put("小行星",imageUtil.getImage("小行星.png"));
        imgMap.put("太阳",imageUtil.getImage("太阳.png"));
        imgMap.put("水星",imageUtil.getImage("水星.png"));
        imgMap.put("金星",imageUtil.getImage("金星.png"));
        imgMap.put("地球",imageUtil.getImage("地球.png"));
        imgMap.put("月球",imageUtil.getImage("月球.png"));
        imgMap.put("火星",imageUtil.getImage("火星.png"));
        imgMap.put("木星",imageUtil.getImage("木星.png"));
        imgMap.put("土星",imageUtil.getImage("土星.png"));
        imgMap.put("天王星",imageUtil.getImage("天王星.png"));
        imgMap.put("海王星",imageUtil.getImage("海王星.png"));
    }

    private imageUtil() {

    }

    public static Image getImage(String imgName){
        BufferedImage img=null;
        try {
            //使用BufferedImage
            URL url =imageUtil.class.getClassLoader()
                    .getResource(Constant.IMG_PATH_PRE+imgName);
            //将URL路径下的资源读取到内存
            img= ImageIO.read(url);
        }catch(IOException e){
            throw new RuntimeException(e);
        }
        return img;
    }
}
